package xin.lhuo.we.server.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;
import xin.lhuo.we.server.entity.Today;

import java.util.Date;
import java.util.List;

/**
 * @author Lhuo
 * @date 2019/6/18 0:28
 */
@Mapper
@Component
public interface TodayMapper {
    @Insert("insert into we_today (user_id,wakeup_time,wakeup_score,sleep_time,sleep_score,study_time,study_score," +
            "read_book_time,read_book_score,exercise,mood,quarrel,expenditure,others,others_score,today,role,total_score)" +
            "values(#{userId},#{wakeupTime},#{wakeupScore},#{sleepTime},#{sleepScore},#{studyTime},#{studyScore}," +
            "#{readBookTime},#{readBookScore},#{exercise},#{mood},#{quarrel},#{expenditure},#{others},#{othersScore}," +
            "#{today},#{role},#{totalScore})")
    void saveToday(Today today);

    @Select("select * from we_today where user_id = #{userId} order by id desc")
    @Results(id = "today",
            value = {
                    @Result(column = "id", property = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "user_id", property = "userId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "wakeup_time", property = "wakeupTime", javaType = String.class, jdbcType = JdbcType.VARCHAR),
                    @Result(column = "wakeup_score", property = "wakeupScore", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "sleep_time", property = "sleepTime", javaType = String.class, jdbcType = JdbcType.VARCHAR),
                    @Result(column = "sleep_score", property = "sleepScore", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "study_time",property = "studyTime",javaType = String.class,jdbcType = JdbcType.VARCHAR),
                    @Result(column = "study_score",property = "studyScore",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "read_book_time",property = "readBookTime",javaType = String.class,jdbcType = JdbcType.VARCHAR),
                    @Result(column = "read_book_score",property = "readBookScore",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "exercise",property = "exercise",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "mood",property = "mood",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "quarrel",property = "quarrel",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "expenditure",property = "expenditure",javaType = Double.class,jdbcType = JdbcType.DOUBLE),
                    @Result(column = "others",property = "others",javaType = String.class,jdbcType = JdbcType.VARCHAR),
                    @Result(column = "others_score",property = "othersScore",javaType = Integer.class,jdbcType = JdbcType.INTEGER),
                    @Result(column = "today",property = "today",javaType = Date.class,jdbcType = JdbcType.DATE),
                    @Result(column = "role",property = "role",javaType = String.class,jdbcType = JdbcType.VARCHAR),
                    @Result(column = "total_score",property = "totalScore",javaType = Integer.class,jdbcType = JdbcType.INTEGER)
            })
    List<Today> getTodayForUserId(@Param("userId") Integer userId);

}
